home *** CD-ROM | disk | FTP | other *** search
-
- /* outxtxy---outextxy,p847 */
- #include <alloc.h>
- #include <graphics.h>
- char label [] = "This is a label";
- main()
- {
- int graphdriver = DETECT, graphmode, xmax, ymax,
- xsize, ysize, x, y, c;
- void *i_buf;
- /* Detect and initialize graphics system */
- initgraph(&graphdriver, &graphmode, "c:\\turboc");
- /* Draw a small marker and save it in a buffer */
- lineto<5,0>;
- moveto<0,0>;
- lineto<0,5>;
- /* Allocate buffer -- we skip error checking, but you
- * shouldn't */
- i_buf = malloc(imagesize(0,0,5,5));
- getimage(0,0,5,5, i_buf);
- cleardevice();
- /* Display instructions for user */
- outtextxy(10, getmaxy()-20,"q = exit, p = place label, "
- "h=left, j=down, k=up, l=right");
- /* Define a viewport */
- xmax = getmaxx();
- ymax = getmaxy();
- xsize = xmax - 100;
- ysize = ymax - 60;
- setviewport(50, 30, xsize+50, ysize+30, 1);
- setfillstyle(SOLID_FILL, RED);
- bar3d(0,0,xsize,ysize,0,1);
- setcolor(YELLOW);
- settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 4);
- settextjustify(LEFT_TEXT, BOTTOM_TEXT);
- /* Ask user to position marker and press
- 'p' to place a label or 'q' to quit. */
- x = xsize/2;
- y = ysize/2;
- putimage(x,y,i_buf,XOR_PUT);
- while((c = getch()) != 'q')
- {
- /* First erase at last position */
- putimage(x,y,i_buf,XOR_PUT);
- switch(c)
- {
- case 'h': x -= 2; /* 2 pixels left */
- break;
- case 'l': x += 2; /* 2 pixels right */
- break;
- case 'j': y += 2; /* 2 pixels down */
- break;
- case 'k': y -= 2; /* 2 pixels up */
- break;
- /* If it's 'p' place label using outtextxy */
- case 'p': outtextxy(x,y,label);
- break;
- }
- /* Redraw at new position */
- putimage(x,y,i_buf,XOR_PUT);
- }
- /* Close graphics system when done */
- closegraph();
- }